﻿<?xml version="1.0" encoding="UTF-8" ?>
<sqlMap namespace="Account"
xmlns="http://ibatis.apache.org/mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >

  <alias>
    <typeAlias alias="HundredsBool" type="MyBatis.DataMapper.SqlClient.Test.Domain.HundredsTypeHandlerCallback, MyBatis.DataMapper.SqlClient.Test"/>
  </alias>
  
  <resultMaps>

    <resultMap id="account-result"  class="Account" >
      <result property="id"           column="Account_ID"/>
      <result property="FirstName"    column="Account_FirstName"/>
      <result property="LastName"     column="Account_LastName"/>
      <result property="EmailAddress" column="Account_Email" nullValue="no_email@provided.com"/>
      <result property="BannerOption" column="Account_Banner_Option" dbType="Varchar" type="bool"/>
      <result property="CartOption"	column="Account_Cart_Option" typeHandler="HundredsBool"/>
    </resultMap>
    
  </resultMaps>
  
  <statements>

    <select id="NVelocity.Simple" resultMap="account-result" parameterClass="map">
      select * from Accounts where Account_Id= $account.id
    </select>

    <select id="NVelocity.If" resultClass="Account" remapResults="true" parameterClass="map">
      SELECT
      Account_ID as Id,

      #if($account.FirstName == "Joe")
      Account_FirstName as FirstName,
      #elseif($account.LastName == "Dalton")
      Account_LastName as LastName,
      #end

      Account_Email as EmailAddress
      FROM
      Accounts
      where Account_Id= $account.id
    </select>

    <select id="NVelocity.InlineParameter" resultClass="Account">
      select
      Account_ID			as Id,
      Account_FirstName	as FirstName,
      Account_LastName	as LastName,
      Account_Email		as EmailAddress
      from Accounts
      #if($LastName == "Dalton")
      where Account_LastName = @{LastName,column=Account_LastName}
      #end
    </select>

    <select id="NVelocity.For" parameterClass="list" resultClass="Account">
      <![CDATA[ 
      select
      Account_ID			as Id,
      Account_FirstName	as FirstName,
      Account_LastName	as LastName,
      Account_Email		as EmailAddress
      from Accounts
      WHERE Account_ID IN 
      (
        #foreach($i in $integers)
          $i
          #if($velocityCount < $integers.count) , #end
        #end
      )
      ]]>
    </select>

    <procedure id="NVelocity.Procedure" parameterClass="map">
      ps_InsertAccountWithDefault
      @{account.Id,column=Account_ID}
      ,@{account.FirstName,column=Account_FirstName}
      ,@{account.LastName,column=Account_LastName}
      ,@{account.EmailAddress,column=Account_Email,nullValue=no_email@provided.com}
      #if( $account.NullBannerOption  )
      ,@{account.NullBannerOption,column=Account_Banner_Option,dbType=Varchar,type=bool}
      #end
      ,@{account.CartOption,column=Account_Cart_Option,handler=HundredsBool}
    </procedure >
    
  </statements >
  
</sqlMap >
